package cn.sf.sufingadminconsumer.controller;

import cn.sf.pojo.Admin;
import cn.sf.sufingadminconsumer.service.FoulService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

@RestController
@CrossOrigin("*")
public class FoulController {

  @Resource private FoulService foulService;

  @RequestMapping("/selectAllFoulInfo")
  public PageInfo<Admin> selectAllFoulInfo(
      Model model, @RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum) {

    PageHelper.startPage(pageNum, 2);
    List<Admin> adminList = foulService.selectAllFoulInfo();
    PageInfo<Admin> pageInfo = new PageInfo<>(adminList);
    model.addAttribute("pageInfo", pageInfo);
    System.out.println("查询封禁名单");
    return pageInfo;
  }

  @RequestMapping("/selectFoulById")
  public List<Admin> selectFoulById(long adminId) {

    System.out.println("根据封禁id查询信息");
    return foulService.selectFoulById(adminId);
  }

  @RequestMapping("/selectFoulByType")
  public List<Admin> selectFoulByType(String foulType) {

    System.out.println("根据封禁id查询信息");
    return foulService.selectFoulByType(foulType);
  }

  @RequestMapping("/insertFoulInfo")
  public String insertFoulInfo(Admin admin) {
    int result = foulService.insertFoulInfo(admin);
    if (result > 0) {
      return "success";
    } else {
      return "false";
    }
  }

  @RequestMapping("/updateFoulInfo")
  public String updateFoulInfo(Admin admin) {
    int result = foulService.updateFoulInfo(admin);
    if (result > 0) {
      return "success";
    } else {
      return "false";
    }
  }

  @RequestMapping("/deleteFoulInfo")
  public String deleteFoulInfo(long adminUserId) {
    int result = foulService.deleteFoulInfo(adminUserId);
    if (result > 0) {
      return "success";
    } else {
      return "false";
    }
  }
}
